package br.com.sigad.servlets.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

public class RecuperadorDeParametrosDaRequisicao {

	private JSONObject parametros;

	public RecuperadorDeParametrosDaRequisicao(HttpServletRequest request) {

		StringBuffer sb = new StringBuffer();
		try {
			BufferedReader reader = request.getReader();
			String line = null;
			while ((line = reader.readLine()) != null) {
				sb.append(line);
			}

			JSONParser parser = new JSONParser();
			parametros = (JSONObject) parser.parse(sb.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}

	}

	public Map<String, String> getParametros() {
		if (parametros == null) {
			return new HashMap<String, String>(0);
		}
		return parametros;
	}
}
